package org.hgvc.webapp.ets.jsf.beans.admin;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.faces.model.SelectItem;

import org.hgvc.webapp.ets.bo.Agreement;
import org.hgvc.webapp.ets.bo.Invoice;
import org.hgvc.webapp.ets.bo.InvoiceDtl;
import org.hgvc.webapp.ets.bo.Payment;
import org.hgvc.webapp.ets.constant.CommonConstant;
import org.hgvc.webapp.ets.spring.service.MemberService;
import org.jocsb.base.AbstractBean;
import org.jocsb.base.exception.BaseException;
import org.jocsb.base.util.SpringUtils;


public class AdminMemberInovicePaymentBean extends AbstractBean {

	public static final String BEAN_NAME="adminMemberInovicePaymentBean";
	private MemberService memberService;
	private Agreement agreement;
	private Invoice invoice;
	private InvoiceDtl invoiceDtl;
	private String name;
	private String cardNo1;
	private String cardNo2;
	private String cardNo3;
	private String cardNo4;
	private String cvcNo;
	private String cardType;
	private Date expDate;
	private Payment payment;
	private List<SelectItem> paymentMethodList;
	private String paymentMethod;
	private boolean cashFlag = false;
	private boolean checkFlag = false;
	private boolean creditCardFlag = false;
	private String chequeno;
	
	
	private static final String NAV_PAYMENT="adminMemberInvPayment";
	private static final String NAV_PAYMENT_ACK="adminMemberInvPaymentAck";
	
	public MemberService getMemberService() {
		return memberService;
	}
	public void setMemberService(MemberService memberService) {
		this.memberService = memberService;
	}
	
	
	
	public String getPaymentMethod() {
		return paymentMethod;
	}
	public void setPaymentMethod(String paymentMethod) {
		this.paymentMethod = paymentMethod;
		if(paymentMethod.equalsIgnoreCase(CommonConstant.PAYMENT_METHOD_CASH)){
			cashFlag = true;
			checkFlag = false;
			creditCardFlag = false;
		}else if(paymentMethod.equalsIgnoreCase(CommonConstant.PAYMENT_METHOD_CHEQUE)){
			cashFlag = false;
			checkFlag = true;
			creditCardFlag = false;
		}else if(paymentMethod.equalsIgnoreCase(CommonConstant.PAYMENT_METHOD_CREDITCARD)){
			cashFlag = false;
			checkFlag = false;
			creditCardFlag = true;
		}
	}
	public List<SelectItem> getPaymentMethodList() {
		paymentMethodList = new ArrayList<SelectItem>();
		SelectItem item1 = new SelectItem(CommonConstant.PAYMENT_METHOD_CASH
				,SpringUtils.getMessage(CommonConstant.PAYMENT_METHOD_CASH, new Object[]{}));
		SelectItem item2 = new SelectItem(CommonConstant.PAYMENT_METHOD_CHEQUE
				,SpringUtils.getMessage(CommonConstant.PAYMENT_METHOD_CHEQUE, new Object[]{}));
		SelectItem item3 = new SelectItem(CommonConstant.PAYMENT_METHOD_CREDITCARD
				,SpringUtils.getMessage(CommonConstant.PAYMENT_METHOD_CREDITCARD, new Object[]{}));
		paymentMethodList.add(item1);
		paymentMethodList.add(item2);
		paymentMethodList.add(item3);
		return paymentMethodList;
	}
	
	
	public String navigateInvoicePayment(Agreement agreement,Invoice invoice,InvoiceDtl invoiceDtl){
		this.agreement = agreement;
		this.invoice = invoice;
		this.invoiceDtl = invoiceDtl;
		return NAV_PAYMENT;
	}
	
	
	public String confirmPaymentAction(){
		try{
			payment = memberService.memberMakePayment(agreement, getThisUser(), invoice.getInvoiceAmount().doubleValue(), invoice.getInvoiceAmount().doubleValue(), invoice, invoiceDtl);
		}catch(BaseException ex){
			ex.printStackTrace();
			initErrorBean(ex);
		}
		return NAV_PAYMENT_ACK;
	}
	public Agreement getAgreement() {
		return agreement;
	}
	public void setAgreement(Agreement agreement) {
		this.agreement = agreement;
	}
	public Invoice getInvoice() {
		return invoice;
	}
	public void setInvoice(Invoice invoice) {
		this.invoice = invoice;
	}
	public InvoiceDtl getInvoiceDtl() {
		return invoiceDtl;
	}
	public void setInvoiceDtl(InvoiceDtl invoiceDtl) {
		this.invoiceDtl = invoiceDtl;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getCardNo1() {
		return cardNo1;
	}
	public void setCardNo1(String cardNo1) {
		this.cardNo1 = cardNo1;
	}
	public String getCardNo2() {
		return cardNo2;
	}
	public void setCardNo2(String cardNo2) {
		this.cardNo2 = cardNo2;
	}
	public String getCardNo3() {
		return cardNo3;
	}
	public void setCardNo3(String cardNo3) {
		this.cardNo3 = cardNo3;
	}
	public String getCardNo4() {
		return cardNo4;
	}
	public void setCardNo4(String cardNo4) {
		this.cardNo4 = cardNo4;
	}
	public String getCvcNo() {
		return cvcNo;
	}
	public void setCvcNo(String cvcNo) {
		this.cvcNo = cvcNo;
	}
	public String getCardType() {
		return cardType;
	}
	public void setCardType(String cardType) {
		this.cardType = cardType;
	}
	public Date getExpDate() {
		return expDate;
	}
	public void setExpDate(Date expDate) {
		this.expDate = expDate;
	}
	public Payment getPayment() {
		return payment;
	}
	public void setPayment(Payment payment) {
		this.payment = payment;
	}
	public boolean isCashFlag() {
		return cashFlag;
	}
	public void setCashFlag(boolean cashFlag) {
		this.cashFlag = cashFlag;
	}
	public boolean isCheckFlag() {
		return checkFlag;
	}
	public void setCheckFlag(boolean checkFlag) {
		this.checkFlag = checkFlag;
	}
	public boolean isCreditCardFlag() {
		return creditCardFlag;
	}
	public void setCreditCardFlag(boolean creditCardFlag) {
		this.creditCardFlag = creditCardFlag;
	}
	public String getChequeno() {
		return chequeno;
	}
	public void setChequeno(String chequeno) {
		this.chequeno = chequeno;
	}
	
	
}